const mysql = require('mysql2/promise');

async function main() {
    const connection = await mysql.createConnection({
        host: 'localhost',
        user: 'lv',
        password: '050227LLL',
        database: 'userdatabase'
    });
    try {
        await connection.execute('CREATE TABLE IF NOT EXISTS customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))');
        const [result] = await connection.execute('INSERT INTO customers (name, address) VALUES (?, ?)', ['John', 'Highway 21']);
        console.log(result.affectedRows, 'record inserted.');
        const [rows] = await connection.execute('SELECT * FROM customers');
        console.log(rows);
    } catch (error) {
        console.error('Error:', error);
    } finally {
        connection.end();
    }
}

main();